package com.atbeijing.bigdata.spark.core.wc

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

// Driver类
object Spark04_WordCount {

    def main(args: Array[String]): Unit = {


        val conf = new SparkConf().setMaster("local[*]").setAppName("WordCount")
        val sc = new SparkContext(conf)

        val lines: RDD[String] = sc.textFile("data/word.txt")
        val words: RDD[String] = lines.flatMap(_.split(" "))
        val wordToOne: RDD[(String, Int)] = words.map((_, 1))
        val wordToCount: RDD[(String, Int)] = wordToOne.reduceByKey(_ + _)

        //wordToCount.collect().foreach(println)

        sc.stop()

    }
}
